Skip to content

Conversation

stevensJourney
Copy link
Collaborator

@stevensJourney stevensJourney commented Aug 4, 2025

Overview

The PowerSync Node.js SDK currently provides both ESM and CommonJS exports for compatibility with different environments. However, some related packages such as the Drizzle and Kysely drivers export ESM JavaScript without explicitly declaring the package as an ES module.

While this isn't an issue for bundled applications, it causes problems when the packages are imported directly into a Node.js application. In such cases, Node.js assumes the packages use CommonJS and fails to load them due to the presence of ESM syntax like import and export.

For additional context. See microsoft/TypeScript#60663

This PR updates the affected packages to explicitly export both ESM and CommonJS (now added via Rollup). As with other packages in this repo - modules are compiled with TypeScript by targeting ES. Rollup is used to compile a CommonJS export which is declared in the package.json file.

A small test suite has also been added to verify that the packages load correctly in both environments.

A test for checking package exports via the Are The Types Wrong CLI has been added for relevant packages. Most packages have been updated with tests. Testing focus has been applied to packages which might be used in a Node.js environment. React native specific packages are not modified in this PR.

Package Changes Summary

  • @powersync/attachments: Added a CJS export which is generated via Rollup.
  • @powersync/common: Added CJS Type declarations.
  • @powersync/drizzle-driver: Added a CJS export which is generated via Rollup.
  • @powersync/kysely-driver: Added a CJS export which is generated via Rollup.
  • @powersync/node: Added CJS Type declarations
  • @powersync/react: Declared the module as a module. We currently only provide ES exports for this package.
  • @powersync/vue: Declared the module as a module. We currently only provide ES exports for this package.
  • @powersync/tanstack-react-query: Declared the module as a module. We currently only provide ES exports for this package.

Copy link

changeset-bot bot commented Aug 4, 2025

🦋 Changeset detected

Latest commit: 3a6cae5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@powersync/drizzle-driver Minor
@powersync/kysely-driver Minor
@powersync/attachments Minor
@powersync/common Minor
@powersync/node Minor
@powersync/tanstack-react-query Minor
@powersync/react Minor
@powersync/vue Minor
@powersync/adapter-sql-js Patch
@powersync/op-sqlite Patch
@powersync/react-native Patch
@powersync/web Patch
@powersync/diagnostics-app Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@stevensJourney stevensJourney marked this pull request as ready for review August 5, 2025 08:43
Copy link
Contributor

@rkistner rkistner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great - the arethetypeswrong tool and docs gives by far the best explanation I've seen of the issues and what needs to be done to fix them.

@stevensJourney stevensJourney merged commit 7ad251a into main Aug 5, 2025
9 checks passed
@stevensJourney stevensJourney deleted the esm-commonjs branch August 5, 2025 15:00
whygee-dev pushed a commit to whygee-dev/powersync-js that referenced this pull request Oct 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants